﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/MainTemplate.Master" AutoEventWireup="true" CodeBehind="Order.aspx.cs" Inherits="Enterprise.Admin.Order" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <link href="../Content/Widget/kindeditor/plugins/code/prettify.css" rel="stylesheet" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <table id="table_list"></table>
    <div id="search_order">
        <form id="search_order_form" action="Handle/Order/GetListJson.aspx" method="post">
        </form>
    </div>
    <div id="add_order">
        <form id="add_order_form" action="Handle/Order/Add.aspx" method="post">
        </form>
    </div>
    <div id="edit_order">
        <form id="edit_order_form" action="Handle/Order/Edit.aspx" method="post">
        </form>
    </div>
    <script type="text/javascript">
        $(document).ready(function () {
            var tableList = $("#table_list").datagrid({
                title: '订单列表',
                fit: true,
                nowrap: false,
                autoRowHeight: false,
                striped: true,
                collapsible: true,
                url: 'Handle/Order/GetListJson.aspx',
                idField: 'id',
                fitColumns: true,
                singleSelect: true,
                onClickRow: function (rowIndex) {
                    $('#table_list').datagrid("unselectRow", rowIndex);
                },
                columns: [[
                         { title: 'Id', field: 'id', width: 280, align: 'center', checkbox: true },
                         { title: '编号', field: 'CoCode', width: 180, align: 'center' },
                         { title: '买家', field: 'CoBuyerName', width: 180, align: 'center' },
                         { title: '手机', field: 'CoMobile', width: 180, align: 'center' },
                         { title: '电话', field: 'CoTelePhone', width: 180, align: 'center' },
                         { title: '总金额', field: 'CoTotalAmount', width: 180, align: 'center' },
                         {
                             title: '修改', field: 'OpEdit', width: 80, align: 'center', formatter: function (value, rec) {
                                 return '<a href="javascript:void(0);" mce_href="#" onclick="edit(\'' + rec.id + '\')">修改</a> ';
                             }
                         },
                         {
                             title: '删除', field: 'OpDelete', width: 80, align: 'center', formatter: function (value, rec) {
                                 return '<a href="javascript:void(0);" mce_href="#" onclick="del(\'' + rec.id + '\')">删除</a> ';

                             }
                         }
                ]],
                pagination: true,
                rownumbers: true,
                toolbar: [{
                    text: '添加',
                    iconCls: 'icon-add',
                    handler: function () {
                        add();
                    }
                }, {
                    text: '修改',
                    iconCls: 'icon-edit',
                    handler: function () {
                        var selectData = $('#table_list').datagrid('getSelected');
                        if (selectData == null) {
                            $.messager.show({
                                title: '提示',
                                msg: '请选择要修改记录！',
                                timeout: 5000,
                                showType: 'fade'
                            });
                        } else {
                            edit(selectData.id);
                        }
                    }
                }, {
                    text: '删除',
                    iconCls: 'icon-remove',
                    handler: function () {
                        var selectData = $('#table_list').datagrid('getSelected');
                        if (selectData == null) {
                            $.messager.show({
                                title: '提示',
                                msg: '请选择要删除记录！',
                                timeout: 5000,
                                showType: 'fade'
                            });
                        } else {
                            del(selectData.id);
                        }
                    }
                }, {
                    text: '查找',
                    iconCls: 'icon-search',
                    handler: function () {
                        $('#search_order').dialog("open");
                    }
                }]
            });
            $('#add_order').dialog({
                title: '添加订单',
                width: 750,
                height: 500,
                closed: true,
                buttons: [{
                    text: '保存',
                    iconCls: 'icon-ok',
                    handler: function () {
                        addSave(function () { });
                    }
                }, {
                    text: '关闭',
                    handler: function () {
                        $('#add_order').dialog('close');
                    }
                }]
            });
            $('#edit_order').dialog({
                title: '修改订单',
                width: 750,
                height: 500,
                closed: true,
                buttons: [{
                    text: '保存',
                    iconCls: 'icon-ok',
                    handler: function () {
                        editSave();
                    }
                }, {
                    text: '关闭',
                    handler: function () {
                        $('#edit_order').dialog('close');
                    }
                }]
            });
            $('#search_order').dialog({
                title: '检索订单',
                width: 400,
                height: 250,
                closed: true,
                buttons: [{
                    text: '查找',
                    iconCls: 'icon-ok',
                    handler: function () {
                        tableList.datagrid("reload", $('#search_order_form').serializeObject());
                    }
                }, {
                    text: '关闭',
                    handler: function () {
                        $('#search_order').dialog('close');
                    }
                }]
            });
            $('#edit_order_form').form({
                onBeforeLoad: function () {
                },
                onLoadSuccess: function () {
                    $('#edit_order').dialog("open");
                },
                onLoadError: function () {
                }
            });
            //获取订单详细
            function edit(id) {
                $('#edit_order_form').form('load', 'Handle/Order/GetDetailJson.aspx?id=' + id);
            }
            function del(id) {
                $.messager.confirm("提示", "确认删除?", function (b) {
                    if (b) {
                        $.ajax({
                            type: "POST",
                            url: "Handle/Order/Delete.aspx",
                            data: { id: id },
                            success: function (msg) {
                                $.messager.show({
                                    title: '提示',
                                    msg: msg.message,
                                    timeout: 5000,
                                    showType: 'fade'
                                });
                                if (msg.state)
                                    $("#table_list").datagrid("reload");
                            },
                            error: function () {
                                $.messager.show({
                                    title: '提示',
                                    msg: '删除失败！',
                                    timeout: 5000,
                                    showType: 'fade'
                                });
                            }
                        });
                    }
                });

            }
        });
        function add() {
            $('#add_order').dialog("open");
        }
        //添加 保存
        function addSave() {
            $.ajax({
                type: "POST",
                url: "Handle/Order/Add.aspx",
                data: $('#add_order_form').serialize(),
                success: function (msg) {
                    $.messager.show({
                        title: '提示',
                        msg: msg.message,
                        timeout: 5000,
                        showType: 'fade'
                    });
                    if (msg.state) {
                        $("#table_list").datagrid("reload");
                        $('#add_order_form')[0].reset();
                    }
                },
                error: function () {
                    $.messager.show({
                        title: '提示',
                        msg: '保存失败！',
                        timeout: 5000,
                        showType: 'fade'
                    });
                }
            });
        }
        //编辑保存
        function editSave() {
            $.ajax({
                type: "POST",
                url: "Handle/Order/Edit.aspx",
                data: $('#edit_order_form').serialize(),
                success: function (msg) {
                    $.messager.show({
                        title: '提示',
                        msg: msg.message,
                        timeout: 5000,
                        showType: 'fade'
                    });
                    if (msg.state)
                        $("#table_list").datagrid("reload");
                },
                error: function () {
                    $.messager.show({
                        title: '提示',
                        msg: '保存失败！',
                        timeout: 5000,
                        showType: 'fade'
                    });
                }
            });
        }
    </script>
    <script src="../Content/Widget/kindeditor/kindeditor-min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../Content/Widget/kindeditor/lang/zh_CN.js" type="text/javascript" charset="utf-8"></script>
    <script src="../Content/Widget/kindeditor/plugins/code/prettify.js" type="text/javascript" charset="utf-8"></script>
    <script src="../Content/Widget/jquery.json.min.js" type="text/javascript" charset="utf-8"></script>
</asp:Content>
